//
//  VC_CourseSelectedWorks.m
//  yjw-winner
//
//  Created by Kae on 2018/9/5.
//  Copyright © 2018年 Shanghai decade financial information service co., LTD. All rights reserved.
//

#import "VC_CourseSelectedWorks.h"
#import "Cell_SelectedWorks.h"
#import "Cell_PPT.h"

@interface Model_CourseSelectedWorks : NSObject
@property (nonatomic, copy) NSString *identifier;
@property (nonatomic, assign) CGFloat cellHeight;
@property (nonatomic, strong) NSArray *dataArray;
@end
@implementation Model_CourseSelectedWorks

@end

@interface VC_CourseSelectedWorks ()<UITableViewDelegate, UITableViewDataSource> {
    UITableView *_tableView;
}
@property (nonatomic, strong) NSArray *dataArray;
@property (nonatomic, strong) UIView *tableViewHeaderView;
@end

@implementation VC_CourseSelectedWorks
- (NSArray *)dataArray {
    if (!_dataArray) {
        Model_CourseSelectedWorks *model0 = [[Model_CourseSelectedWorks alloc] init];
        model0.identifier = @"selectedworksIdentifier";
        model0.dataArray = @[@"", @"", @"", @"", @""];
        model0.cellHeight = 48.0f;
        
        Model_CourseSelectedWorks *model1 = [[Model_CourseSelectedWorks alloc] init];
        model1.identifier = @"pptIdentifier";
        model1.dataArray = @[@""];
        model1.cellHeight = 265.0f;
        _dataArray = @[model0,
                       model1];
    }
    return _dataArray;
}
- (UIView *)tableViewHeaderView {
    if (!_tableViewHeaderView) {
        _tableViewHeaderView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, 80)];
        _tableViewHeaderView.backgroundColor = [UIColor whiteColor];
    }
    return _tableViewHeaderView;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    [self tableViewInit];
}
- (void)viewDidLayoutSubviews {
    [super viewDidLayoutSubviews];
    _tableView.frame = self.view.bounds;
}

- (void)tableViewInit {
    _tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStyleGrouped];
    _tableView.showsVerticalScrollIndicator = NO;
    _tableView.showsHorizontalScrollIndicator = NO;
    _tableView.delegate = self;
    _tableView.dataSource = self;
    _tableView.separatorInset = UIEdgeInsetsMake(0, 15, 0, 15);
    _tableView.tableHeaderView = self.tableViewHeaderView;
    _tableView.tableFooterView = [UIView new];
    [self.view addSubview:_tableView];
}


#pragma mark --mark UITableViewDelegate UITableViewDataSource

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    Model_CourseSelectedWorks *model = self.dataArray[indexPath.section];
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:model.identifier];
    if (!cell) {
        if ([model.identifier isEqualToString:@"selectedworksIdentifier"]) {
            cell = [[Cell_SelectedWorks alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:model.identifier];
        }else if ([model.identifier isEqualToString:@"pptIdentifier"]) {
            cell = [[Cell_PPT alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:model.identifier];
        }else {
            cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:model.identifier];
        }
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return self.dataArray.count;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    Model_CourseSelectedWorks *model = self.dataArray[section];
    return model.dataArray.count;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    Model_CourseSelectedWorks *model = self.dataArray[indexPath.section];
    return model.cellHeight;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    Model_CourseSelectedWorks *model = self.dataArray[section];
    UIView *view;
    if ([model.identifier isEqualToString:@"selectedworksIdentifier"]) {
        view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, 50)];
        UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 5, view.bounds.size.width, view.bounds.size.height - 5)];
        titleLabel.font = [UIFont systemFontOfSize:13];
        titleLabel.text = @"   课程列表";
        titleLabel.backgroundColor = [UIColor whiteColor];
        [view addSubview:titleLabel];
    }else {
        view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, 50)];
        UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 5, view.bounds.size.width, view.bounds.size.height - 5)];
        titleLabel.font = [UIFont systemFontOfSize:13];
        titleLabel.text = @"   课程名称";
        titleLabel.backgroundColor = [UIColor whiteColor];
        [view addSubview:titleLabel];
    }
    view.backgroundColor = MJRefreshColor(237, 237, 237);
    return view;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return 50.0f;
}
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
    UIView *view = [UIView new];
    return view;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    return 0.0f;
}

@end
